package cn.enilu.flash.api.utils;

import cn.enilu.flash.bean.excel.ShipOrderExcel;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.jxls.reader.ReaderBuilder;
import org.jxls.reader.XLSReadStatus;
import org.jxls.reader.XLSReader;
import org.xml.sax.SAXException;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Excel2Product {
    private final static String xmlConfig = "importExcel.xml";

    public static List<ShipOrderExcel> excel2List(InputStream inputStream) throws IOException, SAXException, InvalidFormatException {
        InputStream inputXML = new BufferedInputStream(Excel2Product.class.getClassLoader().getResourceAsStream(xmlConfig));
        XLSReader mainReader = ReaderBuilder.buildFromXML(inputXML);
        InputStream inputXLS = new BufferedInputStream(inputStream);
        ShipOrderExcel pro = new ShipOrderExcel();
        List<ShipOrderExcel> pros = new ArrayList<ShipOrderExcel>();
        Map beans = new HashMap<>();
        beans.put("item", pro);
        beans.put("items", pros);
        XLSReadStatus readStatus = mainReader.read(inputXLS, beans);
        return pros;
    }

}